package com.fanfan.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.fanfan.pojo.domain.ResponseResult;
import com.fanfan.pojo.vo.AddArticleDto;
import com.fanfan.pojo.vo.ArticleListVo;
import com.fanfan.pojo.vo.TagListDto;
import com.fanfan.service.ArticleService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article){
        return articleService.add(article);
    }

    @GetMapping("/list")
    public ResponseResult listArticle(Integer pageNum, Integer pageSize, ArticleListVo articleListVo){
        return articleService.articleToList(pageNum,pageSize,articleListVo);
    }

    @GetMapping("/{id}")
    public ResponseResult queryArticle(@PathVariable Long id){
        return articleService.queryArticle(id);
    }
    @PutMapping
    public ResponseResult reviseArticle(@RequestBody AddArticleDto addArticleDto){
        return articleService.reviseArticle(addArticleDto);
    }
    @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable Long id){
        articleService.getBaseMapper().deleteById(id);
        return ResponseResult.okResult();
    }


}
